package com.magic.gre.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.magic.gre.R;
import com.magic.gre.base.activity.BaseMVPActivity;
import com.magic.gre.mvp.contract.ModefyPwsdContract;
import com.magic.gre.mvp.presenter.ModefyPwsdpresenterImpl;
import com.noname.lib_base_java.util.ToastUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author: Lmoumou
 * Date: 2019-01-10 17:00
 * 文件名: ModefyPwsdActivity
 * 描述:
 */
public class ModefyPwsdActivity extends BaseMVPActivity<ModefyPwsdpresenterImpl> implements ModefyPwsdContract.View {

    @BindView(R.id.pwsd_edt)
    EditText pwsdEdt;
    @BindView(R.id.pwsd_edt2)
    EditText pwsdEdt2;

    public static void startThis(Context context,String phone) {
        Intent intent = new Intent(context.getApplicationContext(), ModefyPwsdActivity.class);
        intent.putExtra("phone",phone);
        context.startActivity(intent);
    }

    private String phone;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_modify_pwsd;
    }

    @Override
    protected ModefyPwsdpresenterImpl creatPresenter() {
        return new ModefyPwsdpresenterImpl(this);
    }

    @Override
    protected void netOverride() {

    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        phone=getIntent().getStringExtra("phone");
    }

    @OnClick(value = {R.id.sumbit_bt})
    protected void onClick(View view) {
        switch (view.getId()) {
            case R.id.sumbit_bt:
                modify();
                break;
        }
    }

    private void modify() {
        String pwsd1 = String.valueOf(pwsdEdt.getText());
        String pwsd2 = String.valueOf(pwsdEdt2.getText());

        if (pwsd1.length() < 6 || pwsd1.length() > 20 || pwsd2.length() < 6 || pwsd2.length() > 20) {
            ToastUtil.getInstance().showNormal(this, "密码不得低于6位并且不得高于20位");
            return;
        }

        if (!TextUtils.equals(pwsd1, pwsd2)) {
            ToastUtil.getInstance().showNormal(this, "密码输入不一致");
            return;
        }

        mPresenter.pModify(phone,pwsd1);
    }


    @Override
    public void vModify() {
        LoginActivity.startThis(this);
    }
}
